import { createRouter ,createWebHashHistory } from 'vue-router';
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import useWarehouseStore from '@/stores/warehouse.js';

var routes = [
    {
        path: '/',
        redirect: '/index'
    },
    {
        path: '/warehouse-select',
        component: () => import('@/views/warehouse-select.vue'),
    },
    {
        path: '/index',
        component: () => import('@/views/index.vue'),
    }
];

const router = createRouter({
    history: createWebHashHistory(),
    routes: routes,
    strict: true,
    scrollBehavior: () => ({ left: 0, top: 0 }),
});

router.beforeEach((to, from) => {
    NProgress.start()

    const warehouseStore = useWarehouseStore();
    if (warehouseStore.getWarehouse() == '' && to.path !== '/warehouse-select') {
        return '/warehouse-select';
    }
});

router.afterEach(() => {
    NProgress.done()
  })

export default router;